package com.atguigu.product.products.service.impl;

import com.atguigu.product.products.entity.PmsCategoryBrandRelationEntity;
import com.atguigu.product.products.service.PmsCategoryBrandRelationService;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.Query;

import com.atguigu.product.products.dao.PmsBrandDao;
import com.atguigu.product.products.entity.PmsBrandEntity;
import com.atguigu.product.products.service.PmsBrandService;
import org.springframework.transaction.annotation.Transactional;


@Service("pmsBrandService")
public class PmsBrandServiceImpl extends ServiceImpl<PmsBrandDao, PmsBrandEntity> implements PmsBrandService {
    @Autowired
    private PmsCategoryBrandRelationService pmsCategoryBrandRelationService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<PmsBrandEntity> page = this.page(
                new Query<PmsBrandEntity>().getPage(params),
                new QueryWrapper<PmsBrandEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 根据id修改，并且修改品牌分类关联表
     * @param pmsBrand
     */
    @Transactional
    public void updateDeatil(PmsBrandEntity pmsBrand) {
       this.updateById(pmsBrand);
       //修改品牌分类关联表
        PmsCategoryBrandRelationEntity en=new PmsCategoryBrandRelationEntity();
        en.setBrandId(pmsBrand.getBrandId());
        en.setBrandName(pmsBrand.getName());
        pmsCategoryBrandRelationService.update(en,new UpdateWrapper<PmsCategoryBrandRelationEntity>().eq("brand_id",pmsBrand.getBrandId()));
    }

}